package com.xwaf.platform.web.controller;

import java.io.InputStream;
import java.util.List;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.xwaf.platform.common.excel.easy.excel.ExcelContext;
import com.xwaf.platform.common.excel.easy.excel.result.ExcelImportResult;
import com.xwaf.platform.common.web.BaseController;
import com.xwaf.platform.system.api.entity.auth.User;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@ApiIgnore
@Api(hidden = true)
@Controller("ExcelImport")
@RequestMapping("/x/import")
public class ExcelImportController extends BaseController {

	/**
	 * 
	 * <p>
	 * easypoi导入测试
	 * <p>
	 * 
	 * @author 李聪 <br>
	 * @email xwaf_love@yeah.net <br>
	 * @since JDK 1.8<br>
	 * @date 2019年12月30日 上午9:32:15 <br>
	 * @see 无<br>
	 * @param file
	 * @throws Exception
	 * @demo <br>
	 */
	@ApiOperation(value = "导入Excel", notes = "导入Excel", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
	@RequestMapping(value = "/import", method = RequestMethod.POST)
	public void export(@RequestParam("file") MultipartFile file) throws Exception {
		ExcelContext context = ExcelContext.newInstance("excel/User-config.xml"); // 导入配置文件
		InputStream in = null;
		if (file != null) {
			in = file.getInputStream();
		}
		ExcelImportResult er = context.readExcel("UserExport", in);
		List<User> users = er.getListBean();
		System.out.println("result:=====" + users);
	}
}
